﻿using System;

namespace WPF_TY_UI
{
    public class BusyHelper : IDisposable
    {
        private TYWindow m_window;
        private TYUserControl m_control;
        private TYPage mPage;

        public BusyHelper(TYWindow window, string busyTitle)
        {
            if (window != null)
            {
                m_window = window;
                m_window.BusyTitle = busyTitle;
                m_window.IsBusy = true;
            }
        }

        public BusyHelper(TYUserControl window, string busyTitle)
        {
            if (window != null)
            {
                m_control = window;
                m_control.BusyTitle = busyTitle;
                m_control.IsBusy = true;
            }
        }

        public BusyHelper(TYPage paeg, string busyTitle)
        {
            if (mPage != null)
            {
                mPage = paeg;
                mPage.BusyTitle = busyTitle;
                mPage.IsBusy = true;
            }
        }

        public void Dispose()
        {
            if (m_window != null)
            {
                m_window.IsBusy = false;
            }
            if (m_control != null)
            {
                m_control.IsBusy = false;
            }
            if (mPage != null)
            {
                mPage.IsBusy = false;
            }
        }
    }

}
